<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
     <%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<base href="<%=request.getContextPath()%>/">
	<link rel="stylesheet" type="text/css" href="css/classes.css"/>
	<script src="js/public/jquery-2.1.1.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/private/class.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="class-info">
		<table border="" cellspacing="" cellpadding="" width="100%" height="100%">
			<tr>
				<th>班级名称</th>
				<th>开班时间</th>
				<th>带班老师</th>
				<th></th>
			</tr>
			<c:forEach items="${pages.data }" var="cla">
			<tr>
				<td align="center">${cla.cname }</td>
				<td align="center">${cla.classestime }</td>
				<td align="center">${cla.teacher.tname}</td>
				<td align="center" id="logID"><input type="radio" name="cid" value="${cla.id}"/></td>
			</tr>
			</c:forEach>
		</table>
		</div>
		<div class='page' id="pages">
		<c:if test="${pages.currentPage==1 }"></c:if>
			<div class='page-item first' id='first'><a href="${pages.url }?curPage=1">首页</a></div>
				<c:if test="${pages.currentPage!=1 }">
			<div class='page-item prev' id='prev'><a href="${pages.url }?curPage=${pages.prevPage}">上一页</a></div>
	</c:if>
			<div class='page-item' id='mid'>${pages.currentPage}/${pages.totalSize}</div>
			<c:if test="${pages.currentPage!=pages.totalSize }">
			<div class='page-item next' id='next'><a href="${pages.url }?curPage=${pages.nextPage}">下一页</a></div>
			</c:if>
			<div class='page-item last' id='last'><a href="${pages.url }?curPage=${pages.totalSize}">末页</a></div>
			
		</div>
		<shiro:hasAnyRoles name="admin,teacher"><div id="addclass">
			<button id="addcla">添加班级</button>
		</div>
		
		
	  <div id="delclass">
			<button type="button" id="delcla">删除班级</button>
		</div>
		</shiro:hasAnyRoles>
	</body>
	<script type="text/javascript">
	$("#delcla").click(function(){
		var cid=$("#logID input[type='radio']:checked").val();
		if(typeof(cid)=="undefined"){
			alert("请选择要删除的班级信息");
			return;
		}
	var isDel=confirm("确定删除该班级信息?");
	if(isDel){
		$.ajax({
			url:"cla/del",
			type:"post",
			dataType:"json",
			data:{'cid':cid},
			success:function(data){
				if(data==2){
					alert("删除成功");
					window.location.reload();
				}
				else if(data==1){
					alert("该班级下还有学生，不能删除！");
				}
				else if(data==0){
					alert("删除失败,请重试")
				}
			}
		})
	}
	})
	</script>
</html>
